import coffeetalk.protocol.ioelement as ioelement


class Environment:
    
    def __init__(self,ip,username,group,connectionid,requestid,element=None):
        self.__name__ = 'Environment'
        self.ip = ip
        self.username = username
        self.group = group
        self.connectionid = connectionid
        self.requestid = requestid
        if element != None:
            self.from_element(element)
        self.element = ioelement.IOElement('ENV',{'type':'[Environment]','ip':self.ip,'username':self.username,'group':self.group,'connectionid':self.connectionid,'requestid':self.requestid})
        
    def from_element(self,element):
        try:
            self.ip = element.attribs['ip']
            self.username = element.attribs['username']
            self.group = element.attribs['group']
            self.connectionid = element.attribs['connectionid']
            self.requestid = element.attribs['requestid']
        except:
            raise AttributeError, 'Invalid Environment'
        
    def __repr__(self):
        return str(self.element)
    
    def __str__(self):
        return str(self.element)
    
    
if __name__ == '__main__':
    env = Environment('0.0.0.0','(unknown)','(unknown)','0','0')
    
    print str(env)
    
    print env.element